﻿/**
 * 
 */
function select(){
	
	if(confirm("查询数据？")){
		var stuname=document.getElementById("stuname").value;
		var stuid=document.getElementById("stuid").value;
		var n="selectCon";
		location.href=".../../StudentServlet?method="+n+"&stuname="+stuname+"&stuid="+stuid;		
	}	
}

function selectStu(id){
	if(confirm("查看该信息？")){
		var x="selectStuById";
		location.href=".../../StudentServlet?method="+x+"&stuid="+id;	
	}
}
function editStu(id1){
	if(confirm("编辑该信息？")){
	var y="selectEditStu";
		location.href=".../../StudentServlet?method="+y+"&stuid="+id1;	
	}
}


/**
 * 后台修改学生信息验证
 */
var xmlhttp;
function ckuname() {
	var uname = document.getElementById("uname").value;
	var reg = /^[a-zA-Z]\w{5,9}$/;
	if (!reg.test(uname)) {
		document.getElementById("spuname").innerHTML = "姓名格式不正确";
		return false;
	}
	if (reg.test(uname)) {
		document.getElementById("spuname").innerHTML = "√";
		
	}
	xmlhttp=new XMLHttpRequest();
	xmlhttp.onreadystatechange()=resp;
	var z="ajaxUname";
	xmlhttp.open("get", ".../../StudentServlet?method="+z+"&uname="+uname, true);
	xmlhttp.send(null);
	 return true;
}
function resp(){
	if (xmlhttp.readyState == 4) {
		if (xmlhttp.status == 200) {
			var txt = xmlhttp.responseText;
			if (txt == 0) {
				document.getElementById("spuname").innerHTML = "用户名不能修改";
			
		}
	}
}
}


function ckpwd() {
	var pwd = document.getElementById("pwd").value;
	// document.getElementById("sppwd").style.color="red";
	var pwd1 = /^[a-zA-Z]\w{5,17}$/;
	if (!pwd1.test(pwd)) {
		document.getElementById("sppwd").innerHTML = "长度必须在6-18位之间，只能包含字母，数字，下划线，";
		return false;
	}
	if (pwd1.test(pwd)) {
		document.getElementById("sppwd").innerHTML = "√";
		
	}
	return true;
}


function ckrname() {
	var rname = document.getElementById("rname").value;
	var name1 = /^[\u4e00-\u9fa5]{2,4}$/;
	if (!name1.test(rname)) {
		document.getElementById("sprname").innerHTML = "真实姓名必须为汉字";
		return false;
	}
	if (name1.test(rname)) {
		document.getElementById("sprname").innerHTML = "√";
		
	}
	return true;
}


function ckuid() {
	var uid = document.getElementById("uid").value;
	
	
	var reg=/^[1-9][0-9]{5}(19[0-9]{2}|200[0-9]|2016)(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])[0-9]{3}[0-9xX]$/;

	
	if (!reg.test(uid)) {
		document.getElementById("spuid").innerHTML = "身份证格式不正确";
		return false;
	} 
	if (reg.test(uid)) {
		document.getElementById("spuid").innerHTML = "√";
		
	} 
	return true;
}


function ckphone() {
	var phone = document.getElementById("phone").value;
	var reg = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|17[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
	if (!reg.test(phone)) {
		document.getElementById("spphone").innerHTML = "请正确输入手机号";
		return false;
	}
	if (reg.test(phone)) {
		document.getElementById("spphone").innerHTML = "√";
		
	}
	 return true;
}


function ckaddress() {
	var address = document.getElementById("address").value;
	var str = document.getElementById('address').value.trim();
	if (str.length == 0) {
		document.getElementById("spaddress").innerHTML = "地址栏不能为空";
		return false;
	}
	if (str.length != 0) {
		document.getElementById("spaddress").innerHTML = "√";
		
	}
	return true;
}


function ckemail() {
	var email = document.getElementById("email").value;
	reg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
	if (!reg.test(email)) {
		document.getElementById("spemail").innerHTML = "电子邮箱不能是空,必须包含@,.且必须在@之后";
		return false;
	}
	if (reg.test(email)) {
		document.getElementById("spemail").innerHTML = "√";
		
	}
	return true;
}


function ckall() {
	var flag = ckpwd() && ckrname() && ckuid() && ckphone()&& ckaddress() && ckemail();
	
	if (flag == false) {
		alert("内容填写不完整");
	}
	return flag;
}





function deleteStu(id){
	if(confirm("删除该信息？")){	
		location.href=".../../DeleteStudentHoutaiServlet?stuid="+id;	
		}
}




function sepage(la){	
	var page=document.getElementById("pa").value;
	var reg=/^\d+$/g;
	if(!reg.test(page)){
		alert("只能是正整数，请重新输入");
	}else{
	
	if(la<page){	
		alert("已超出页面范围");
		location.href="StudentServlet?method=selectCon";
		return;
	}else{			
		location.href="StudentServlet?method=selectCon"+"&page="+page;
		return;
	}
	}
}




window.onload = function(){
	document.getElementById("checkbox1").onclick = function(){
		var flag = this.checked;
		var items = document.getElementsByName("checkbox2");
		for(var i = 0; i < items.length; i++){
			items[i].checked = flag;
			}
		}
		var items = document.getElementsByName("checkbox2");
		for(var i = 0; i < items.length; i++){
			items[i].onclick = function(){
				//记录有多少个 items 被选中了
				var number = 0;
				for(var j = 0; j < items.length; j++){
					if(items[j].checked){
						number++;
					}
				}
				document.getElementById("checkbox1").checked = (items.length == number);
			}
		}
	}

function refresh(){
	location.href=".../../StudentServlet?method=selectCon";
}
function freshdetail(id){
	
	var x="selectStuById";
	location.href=".../../StudentServlet?method="+x+"&stuid="+id;	

}

function freshedit(id){
	var y="selectEditStu";
	location.href=".../../StudentServlet?method="+y+"&stuid="+id;	

}


